package cn.richard.home.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import cn.richard.home.api.repository.PictureRepository
import cn.richard.home.model.PicListModel
import kotlinx.coroutines.launch

/**
 *
 * @ProjectName: PicApp
 * @Author: wuzhiguo@aiforward.com
 * @CreateDate: 2021/9/2 2:26 下午
 * @Description:
 */
class PicListViewModel(private val pictureRepository: PictureRepository): ViewModel() {

    private var skip: Int = 0
    private var limit: Int = 30


    val picturesLiveData = MutableLiveData<PicListModel>()


    fun getPicList(categoryId: String, order: String) {
        viewModelScope.launch {
            val tempPictures = pictureRepository.getPictureList(categoryId, limit, skip, order)
            tempPictures.res?.vertical?.let {
                skip += it.size
                picturesLiveData.value = PicListModel(true, it)
            }?: let{
                picturesLiveData.value = PicListModel(false, null)
            }
        }

    }
}